<template>
	<view>
		<u-toast ref="uToast"></u-toast>
		<u-navbar title="账号密码登录" :placeholder="true" @leftClick="goBack"></u-navbar>
		<view class="margin-sm padding-sm bg-white">
			<u--form labelPosition="left" :model="loginData" :rules="rules" ref="uForm" :labelWidth="60">
				<u-form-item label="账号" prop="phone" borderBottom>
					<u--input v-model="loginData.username" border="none" placeholder="请输入用户名"></u--input>
				</u-form-item>
				<u-form-item label="密码" prop="password" borderBottom>
					<u--input v-model="loginData.password" border="none" type="password"
						placeholder="请输入登录密码"></u--input>
				</u-form-item>
			</u--form>
			<button class="cu-btn margin-top bg-tea" style="width: 100%;height: 40px" @click="login()">登录</button>
			<view class="flex justify-center margin-top">
				<text class="text-blue">还没有账号?点此注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginData: {
					username: "",
					password: ""
				},
				rules: {
					'loginData.username': [{
							required: true,
							message: '请输入用户名',
							trigger: ['change', 'blur'],
						},
					],
					'loginData.password': {
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change'],
					}
				}
			}
		},
		methods: {
			login() {
				let that = this;
				uni.showLoading({
					title: '登录中，请稍后'
				});
				uni.$u.http.post('/manager/login', this.loginData).then(res => {
					uni.setStorage({
						key: "UserInfo",
						data: res.data
					});
					console.log("res:"+res.data);
					that.goBack();
				});
			},
			goBack() {
				uni.switchTab({
					url: '/pages/usercenter/index'
				})
			}
		}
	}
</script>

<style>
</style>
